package org.autotestcase.ui.component;

import java.io.IOException;

import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

public class UIDynamicId extends UIOutput {

	public void encodeBegin(FacesContext context) throws IOException {
		String id = (String) getAttributes().get("id");
		String value = (String) getAttributes().get("value");
		
		if (value == null) {
			throw new IllegalArgumentException("The value atributte must be set.");
		}
		
		if (id == null) {
			throw new IllegalArgumentException("The id atributte must be set.");
		}

		String classAttribute = "";
		String styleClass = (String) getAttributes().get("styleClass");
		if (styleClass != null) {
			classAttribute = " class=\"" + styleClass + "\"";
		}
		
//		ResponseWriter writer = context.getResponseWriter();
//		writer.append("<span id=\"" + id + classAttribute + "\"/>");
//		writer.write(value);
		
		getParent().setId(id);
	}

	public void encodeEnd(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		writer.endElement("span");
	}
	
	public String getFamily(){
		return "org.autotestcase.ui.DynamicId";
	}

}
